<?php

namespace app\frontend\controller;

use app\admin\model\Caser;
use think\Controller;
use think\Db;

class News extends Controller
{
    public function index()
    {
        $case = new Caser();
        $casies = $case->table('d_news');
        $title = input('title');
        if (isset($title)) {
            $casies->where('title', 'like', "%{$title}%");
        }
        $cases = $casies->paginate(9);

        $this->assign('cases', $cases);

        echo $this->fetch();
    }

     public function details()
    {
        $id = input('id');

        $cases = Db::table('d_news')->field('id,imagies,title,updated_at')->order('id','desc')->limit(10)->select();
        $case = Db::table('d_news')->where('id',$id)->find();
        $prev = Db::table('d_news')->field('id')->where('id','<',$case['id'])->order('id','desc')->find();
        $next = Db::table('d_news')->field('id')->where('id','>',$case['id'])->order('id','asc')->find();

        $this->assign('case', $case);
        $this->assign('cases', $cases);
        $this->assign('prev', $prev);
        $this->assign('next', $next);
        echo $this->fetch();
    }
}
